package com.ruoyi.wecom.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.vo.wecom.admin.TbWecomCustomerChatGroupPageVO;
import com.ruoyi.business.domain.vo.wecom.admin.TbWecomCustomerPageVO;
import com.ruoyi.business.domain.vo.wecom.admin.TbWecomCustomerVO;
import com.ruoyi.business.service.wecom.ITbWecomExternalContactCustomerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@Validated
@Api(value = "企微客服客户管理", tags = {"企微客服客户管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/wecom/external/contact/customer")
public class WecomExternalContactCustomerController extends BaseController {

    @Resource
    private ITbWecomExternalContactCustomerService tbWecomExternalContactCustomerService;

    /**
     * 客户列表分页查询
     */
    @ApiOperation("分页查询客户列表")
    @GetMapping("/sys-page")
    @SaCheckPermission("wecom:external:customer:page")
    public TableDataInfo<TbWecomCustomerPageVO> sysPageQuery(
        @ApiParam("客户名称") @RequestParam(required = false) String name,
        @ApiParam("外部联系人id") @RequestParam(required = false) String externalUserid,
        @ApiParam("客户性别 0-未知 1-男性 2-女性") @RequestParam(required = false) Integer gender,
        @ApiParam("客户类别 1表示该外部联系人是微信用户，2表示该外部联系人是企业微信用户") @RequestParam(required = false) Integer type,
        @ApiParam("流失状态 0未流失，1已流失") @RequestParam(required = false) Integer followStatus,
        @ApiParam("客户标签列表") @RequestParam(required = false) List<String> tagIds,
        @ApiParam("所属客服列表") @RequestParam(required = false) List<String> userIds,
        @ApiParam("添加来源 0\t未知来源\n" +
            "1\t扫描二维码\n" +
            "2\t搜索手机号\n" +
            "3\t名片分享\n" +
            "4\t群聊\n" +
            "5\t手机通讯录\n" +
            "6\t微信联系人\n" +
            "8\t安装第三方应用时自动添加的客服人员\n" +
            "9\t搜索邮箱\n" +
            "10\t视频号添加\n" +
            "11\t通过日程参与人添加\n" +
            "12\t通过会议参与人添加\n" +
            "13\t添加微信好友对应的企业微信\n" +
            "14\t通过智慧硬件专属客服添加\n" +
            "15\t通过上门服务客服添加\n" +
            "16\t通过获客链接添加\n" +
            "17\t通过定制开发添加\n" +
            "18\t通过需求回复添加\n" +
            "21\t通过第三方售前客服添加\n" +
            "22\t通过可能的商务伙伴添加\n" +
            "24\t通过接受微信账号收到的好友申请添加\n" +
            "201\t内部成员共享\n" +
            "202\t管理员/负责人分配") @RequestParam(required = false) List<String> addWays,
        @ApiParam("筛选添加开始时间") @RequestParam(required = false) Long beginTime,
        @ApiParam("筛选添加结束时间") @RequestParam(required = false) Long endTime,
        PageQuery pageQuery) {
        return tbWecomExternalContactCustomerService.selectSysPageList(gender, type, followStatus, name, externalUserid, tagIds, userIds, addWays, beginTime, endTime, pageQuery);
    }


    /**
     * 所在群聊筛选
     */
    @ApiOperation("所在群聊筛选")
    @GetMapping("/sys-group-page")
    @SaCheckPermission("wecom:external:customer:chat:page")
    public TableDataInfo<TbWecomCustomerChatGroupPageVO> sysGroupPageQuery(
        @ApiParam("所在群聊列表") @RequestParam(required = false) List<String> chatIds,
        @ApiParam("客户类别 1表示该外部联系人是微信用户，2表示该外部联系人是企业微信用户") @RequestParam(required = false) Integer type,
        PageQuery pageQuery) {
        return tbWecomExternalContactCustomerService.selectSysChatGroupPageList(chatIds, type, pageQuery);
    }

    /**
     * 查询客户详情
     */
    @ApiOperation("根据externalUserid查询客户详情")
    @GetMapping("sys-detail/{externalUserid}")
    @SaCheckPermission("wecom:external:customer:detail")
    public R<TbWecomCustomerVO> getInfo(@ApiParam("客户id")
                                                 @NotNull(message = "客户id不能为空")
                                                 @PathVariable("externalUserid") String externalUserid) {
        return R.ok(tbWecomExternalContactCustomerService.sysSelectDetail(externalUserid));
    }


}
